package com.esiag.transformation;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLEventReader;

//import com.esiag.generated.Connect;

public abstract class Decodeur {
	/**
	 * Constructeur de la classe Decodeur permettant de transformer un flux XML en objet
	 */
	private Unmarshaller decodeur = null;
	private Object returnedObject = null;
	private InputStream inputFile = null;
	public Decodeur(){
		
		FileInputStream inputFile = null;
		try {
			/*
			 * 
			 */
			inputFile = new FileInputStream("Xml/connect.xml");
			JAXBContext context = JAXBContext.newInstance("com.esiag.generated");
			decodeur= context.createUnmarshaller();
		
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
	}
	/**
	 * Retourner l'objet 
	 */
	
	public Object decodeObject(){
		try {
			returnedObject = decodeur.unmarshal(inputFile);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 return(returnedObject);
	}
	
	
}
